<%@ page language="java" pageEncoding="UTF-8"
	contentType="text/html;charset=UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
	request.setAttribute("basePath", basePath);
%>
<!DOCTYPE>
<html>
<head>
<title>明细信息</title>
	<%@ include file="/resources/js/easyui/taglibs.jsp"%>
	<%@ include file="/resources/js/easyui/_easyui.jsp"%>
	<%@ include file="/resources/js/easyui/_message.jsp"%>
	<%@ include file="/resources/js/easyui/_viewJS.jsp"%>
</head>

<body class="easyui-layout">
	<form id="addform">
		<table class="tableForm" style="width: 100%;">
			<tr>
				<td>子账户号：${childuser.username}<input type="hidden"
					value="${childuser.userid}" name="userid" /></td>
			</tr>

			<tr>
				<td>
					<ul id="GC_sys_roles">

					</ul>
				</td>
			</tr>

		</table>

	</form>

	<script type="application/javascript">
		
	var user_role = ${sysUserRoles}
	
	function setup(){
		var checkedValues = [];
		var noChanged = true;
		$('input[name="roleid"]:checked').each(function(){ 
			checkedValues.push($(this).val()); 
		}); 
		
		if(checkedValues.length == 0){
			$.messager.alert('提示','至少分配一个权限！','warning');
		}else if(checkedValues.length == user_role.length){
			$.each(checkedValues.sort(function(a,b){return a-b}),function(index){
				if(checkedValues[index] != user_role[index].roleid){
					noChanged = false;
					return false;
				}
			});
		}else{
			noChanged = false;
		}

		if(noChanged){
			$.messager.alert('提示','当前权限设置尚未改变，如有更改后再保存！','warning');
		}else{
			if($("#addform").form('validate')){
 				$.ajax({
					url:'${basePath}web/childuser/setupUserGroup',
					type : 'POST',
					data : $("#addform").serialize(),
					async : false,
					traditional:true,
					error: function (response) {
						ViewHelper.func.ajaxErrorMessage(response);
					},
					success: function (ret) {
						if(ret.result) {
							$.messager.alert('提示信息！',ret.info,'info');
							parent.view.closeSetupWin(1);
							$("#addform").form('clear');
						}else{
							$.messager.alert('提示','保存失败!','error');
						}
					}
				});
			} 
		}
	};;;;;
	
	
	$(function() {
		  $.ajax({
			  type:'GET',
			  url:'${basePath}web/childuser/usergroup.json',
			  dataType:'json',
			  success:function(data){
					 $.each(data,function(i,item){			 
						 $("#GC_sys_roles").append('<li style="list-style-type:none;float:left;margin-left:4px; "><input type="checkbox" name="roleid" value="'+item.userGroupid+'">'+item.textCN+'</li>');
					 });
				  $.each(user_role,function(i,item){
					 $("input[name='roleid'][value='"+item.roleid+"']").attr("checked",'true');
				 });
			  },
			  error:function(){
			  	alert("获取数据失败!");
			  }
		});  
	});

	
	</script>
</body>
</html>
